<template>
  <div class="control-panel">
    <!-- 状态显示 -->
    <div class="status-display">
      <div class="status-indicator" :class="state">
        <i :class="statusIcon"></i>
      </div>
      <div class="status-text">
        <h3>{{ statusText }}</h3>
        <p v-if="currentRecognition" class="recognition-text">
          "{{ currentRecognition }}"
        </p>
      </div>
    </div>

    <!-- 控制按钮 -->
    <div class="control-buttons">
      <!-- 开始对话按钮 -->
      <button 
        v-if="canStart" 
        @click="$emit('start')" 
        class="control-btn start-btn"
        :disabled="!canStart"
      >
        <i class="fas fa-play"></i>
        <span>开始对话</span>
      </button>

      <button 
        v-if="canStop" 
        @click="$emit('stop')" 
        class="control-btn stop-btn"
        :disabled="!canStop"
      >
        <i class="fas fa-stop"></i>
        <span>停止对话</span>
      </button>

      <!-- 打断AI按钮 -->
      <button 
        v-if="canInterrupt" 
        @click="$emit('interrupt')" 
        class="control-btn interrupt-btn"
        :disabled="!canInterrupt"
      >
        <i class="fas fa-hand-paper"></i>
        <span>打断AI</span>
      </button>
    </div>

    <!-- 连接状态指示器 -->
    <div class="connection-status" :class="{ connected: isConnected }">
      <div class="status-dot"></div>
      <span>{{ isConnected ? '已连接' : '未连接' }}</span>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue';

// 定义props
const props = defineProps({
  canStart: {
    type: Boolean,
    default: false
  },
  canStop: {
    type: Boolean,
    default: false
  },
  canInterrupt: {
    type: Boolean,
    default: false
  },
  isConnected: {
    type: Boolean,
    default: false
  },
  state: {
    type: String,
    default: 'disconnected'
  },
  statusText: {
    type: String,
    default: ''
  },
  currentRecognition: {
    type: String,
    default: ''
  }
});

// 定义emits
const emit = defineEmits(['start', 'stop', 'interrupt']);

// 状态图标
const statusIcon = computed(() => {
  switch (props.state) {
    case 'connecting': return 'fas fa-spinner fa-spin';
    case 'connected': return 'fas fa-check-circle';
    case 'listening': return 'fas fa-microphone';
    case 'processing': return 'fas fa-brain';
    case 'speaking': return 'fas fa-volume-up';
    default: return 'fas fa-circle';
  }
});
</script>

<style scoped>
.control-panel {
  padding: 20px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 15px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  margin-top: 20px;
}

.status-display {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  gap: 15px;
}

.status-indicator {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  transition: all 0.3s;
}

.status-indicator.disconnected {
  background: rgba(128, 128, 128, 0.3);
  color: #888;
}

.status-indicator.connecting {
  background: rgba(255, 193, 7, 0.3);
  color: #ffc107;
}

.status-indicator.connected {
  background: rgba(40, 167, 69, 0.3);
  color: #28a745;
}

.status-indicator.listening {
  background: rgba(74, 108, 247, 0.3);
  color: #4a6cf7;
  animation: pulse 2s infinite;
}

.status-indicator.processing {
  background: rgba(255, 107, 107, 0.3);
  color: #ff6b6b;
}

.status-indicator.speaking {
  background: rgba(31, 221, 161, 0.3);
  color: #1fddaa;
  animation: speaking 1s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

@keyframes speaking {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.status-text h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-light);
}

.status-text p {
  margin: 5px 0 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.recognition-text {
  color: var(--primary);
  font-style: italic;
  background: rgba(74, 108, 247, 0.1);
  padding: 5px 10px;
  border-radius: 8px;
  border-left: 3px solid var(--primary);
}

.control-buttons {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-bottom: 15px;
}

.control-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.3s;
  min-width: 120px;
  justify-content: center;
}

.control-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.start-btn {
  background: linear-gradient(135deg, #28a745, #20c997);
  color: white;
}

.start-btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(40, 167, 69, 0.4);
}

.stop-btn {
  background: linear-gradient(135deg, #dc3545, #e74c3c);
  color: white;
}

.stop-btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(220, 53, 69, 0.4);
}

.interrupt-btn {
  background: linear-gradient(135deg, #ffc107, #ffca2c);
  color: #333;
}

.interrupt-btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(255, 193, 7, 0.4);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #888;
  transition: all 0.3s;
}

.connection-status.connected .status-dot {
  background: #28a745;
  box-shadow: 0 0 10px rgba(40, 167, 69, 0.5);
}

.connection-status.connected {
  color: #28a745;
}
</style>